<template>
    <div>
        <el-table :data="getlist" row-key="id" :tree-props="{ children: 'children' }" default-expand-all border
            style="width: 100%">
            <el-table-column prop="id" label="菜单编号" >
            </el-table-column>
            <el-table-column prop="title" label="菜单名称" align="center">
            </el-table-column> 
            <el-table-column prop="pid" label="上级菜单" align="center">
                <template slot-scope="item">
                    <!-- item.row 代表的是table中的每一行数据 -->
                    <div>
                        <!-- {{item.row}} -->
                        <!-- {{ item.row.status == 1 ? "启用" : "禁用" }} -->
                        <el-tag v-if="item.row.pid == 0" type="info">顶级菜单 </el-tag>
                        <el-tag v-if="item.row.pid == 1">系统管理</el-tag>
                        <el-tag v-if="item.row.pid == 2" type="warning">商城管理</el-tag>
                    </div>
                </template>
            </el-table-column>

            <el-table-column prop="icon" label="菜单图标" align="center">
                <template slot-scope="item">
                    <div>
                        <i :class="item.row.icon"></i>
                    </div>
                </template>
                
            </el-table-column>
            <el-table-column prop="url" label="菜单地址">
            </el-table-column>


            <el-table-column prop="status" label="状态" align="center">
                <template slot-scope="item">
                    <!-- item.row 代表的是table中的每一行数据 -->
                    <div>
                        <!-- {{item.row}} -->
                        <!-- {{ item.row.status == 1 ? "启用" : "禁用" }} -->
                        <el-tag v-if="item.row.status == 1" type="success">启用 </el-tag>
                        <el-tag type="danger" v-else> 禁用</el-tag>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template slot-scope="item">
                    <el-button type="primary" icon="el-icon-edit" @click="edit(item.row.id)" circle></el-button>
                    <el-button type="danger" icon="el-icon-delete" @click="del(item.row.id)" circle></el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
import { menudelete } from '../../request/app'
import { mapGetters, mapActions } from 'vuex'
export default {
    data() {
        return {

        };
    },
    computed: {
        ...mapGetters({
            getlist: 'setshop/getstatemenulist'
        })
    },
    mounted() {
        if(this.getlist.length==0){
            // console.log(11111111111111);
             this.ACgetlist()
        }
    },
    methods: {
        ...mapActions({
            ACgetlist: 'setshop/ACgetlist'
        }),

        // 修改
        edit(id){
            // console.log(11111111, id,'id');
            this.$emit('isedit',id)
        },
        // 删除
        del(id) {

            this.$confirm('是否删除该条目录菜单?', '提示', {
                confirmButtonText: '是的',
                cancelButtonText: '不用了',
                type: 'warning'
            }).then(() => {
                // 调用删除接口
                menudelete({
                    id
                }).then(res => {
                    console.log(res);
                    if (res.code == 200) {
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        // 重新渲染
                        this.ACgetlist()
                    } else {
                        this.$message.error(res.msg);
                    }
                })

            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });

        }
    },
    components: {

    },
}
</script>

<style scoped>
</style>
